/* 
 Project     : 48c6c450f1a4a0cc53d9585dc0fee742
 Created on  : Mar 16, 2013, 11:29:15 PM
 Author      : Truong Khuong - khuongxuantruong@gmail.com
 Description :
 Purpose of the stylesheet follows.
 */
var _CONFIG = {
    JQXGRID_ELEMENT: '#jqxGrid_Backend_Categories',
    _TYPE: 'kitchen',
    BINDING_URI: base_url + 'backend/user/binding/',
    EDIT_PANEL_URI: base_url + "backend/user/editpanel",
    EDIT_PANEL_URI2: base_url + "backend/user/editpanel",
    COMMIT_URI: base_url + "backend/user/save",//commit/user/auth_user/ause",
    DELETE_URI: base_url + "backend/excution/delete/user/auth_users/ause",
    RANDOM_STRING_URI   :   base_url + 'backend/user/randomstring',
    PENDING: false,
    PAGE: 0,
    PAGESIZE: 20
};
var _SOPLUGIN = (function() {
    var init = false;
    return {
        RandomPass:function(){
            new backend({
                url: _CONFIG.RANDOM_STRING_URI,
                data: {},
                callback: function(rsdata) {
                    if (rsdata.result < 0) {
                        $.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
                    } else {
                        $('#ause_password').val(rsdata.message);
                    }
                }
            }).call();
        },
        LoadData: function(_page) {
            _CONFIG.PAGE = _page;
            $('#requestDataList').load(_CONFIG.BINDING_URI, {
                pagenum: _CONFIG.PAGE,
                pagesize: _CONFIG.PAGESIZE
            });
        },
        OnInit: function() {
            try {
                if (init)
                    return;
                init = true;
                //grid_element=$('#jqxGrid_Backend_Categories');
                this.LoadData(_CONFIG.PAGE);

            } catch (e) {
                bootbox.alert(e.message);
            }
        },
        AddItem: function() {
            this.EditItem(0);
        },
        AddItemIn: function() {
            this.EditItemIn(0);
        },
        EditItem: function(Id) {
            if (PENDING)
                return false;
            $('#dialog-user>.base-dialog-modal').html('<div class="base_loading" style="display: block;height: 60px"></div>');
            bckdialog({
                title:'User Profile',
                message:$('#dialog-user'),
                buttons: [
                    {
                        text    :'Done',
                        class   :'base_button base_green base-small-border-radius',
                        click   : function() {
                            _SOPLUGIN.Save();
                        }
                    },
                    {
                        text    :'Close',
                        class   :'base_button base_red base-small-border-radius',
                        click   : function() {
                            $(this).dialog("close");
                        }
                    }
                ]
            }).open();
            new backend({
                url: _CONFIG.EDIT_PANEL_URI,
                data: {
                    Id: Id,
                    Type:_CONFIG._TYPE
                },
                callback: function(rsdata) {
                    PENDING = false;
                    if (rsdata.result < 0) {
                        //$.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
                        $('#dialog-user>.base-dialog-modal').html('<span style="color:red">'+rsdata.message+'</span>');
                    } else {
                        $('#dialog-user>.base-dialog-modal').html(rsdata.htmlreponse);
                        $('#dialog-user').dialog('close').dialog('open'); 
                    }
                }
            }).call();
        },
        Save: function() {
            if (PENDING)
                return false;
            var Params = $('#_form_edit_panel_user').serializeObject();
            if(Params.ause_username==="")return;
            if(Params.ause_name==="")return;
            if(Params.ause_email==="")return;
            if(Params.ause_password==="" && $('#ause_id').val()==="")return;
            var _dialog = $('#dialog-user');
            _dialog.parents('.ui-dialog').find('.dialog-pending').show();
            new backend({
                url: _CONFIG.COMMIT_URI,
                data: {
                    Params: Params,
                    ause_id: $('#ause_id').val()
                },
                callback: function(rsdata) {
                    PENDING = false;
                    _dialog.parents('.ui-dialog').find('.dialog-pending').hide();
                    if (rsdata.result < 0) {
                        //$.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
                        bckdialog({type:'error'}).open(rsdata.message);
                        return false;
                    } else {
                        
                        _SOPLUGIN.Cancel();
                        _SOPLUGIN.Refresh();
                        return true;
                    }
                }
            }).call();
            return false;
        },
        OtherAdvand: function() {
            $('.otheradvand').toggle();
        },
        Cancel: function() {
            //$('#_form_edit_panel').parents('.bootbox').modal('hide');
            $('#dialog-user').dialog('close');
        },
        DeleteItem: function(id) {
            backend_delete(_CONFIG.DELETE_URI,id,function(){
                _SOPLUGIN.Refresh();
            });
        },
        RestoreItem: function() {
            accessdenied();
        },
        Permission: function(id) {

        },
        PrivateItem: function() {
            accessdenied();
        },
        Setting: function() {
            bckdialog({
                message: $('#window-sOpt'),
                icon: "<img class='p-a t-7 l-8' src='" + base_url + "/libraries/images/16/option.gif'/>",
                title: 'Setting'
            }).open();
        },
        Refresh: function() {
            this.LoadData(_CONFIG.PAGE);
        }
    };
}());
$(document).ready(function() {
    
});